package helpers;

import java.io.Serializable;

import application.Configuration;
import application.messages.commands.parameters.Coordinates2D;

/**
 * This application is using pixel coordinates (not default OpenGL
 * coordinates), what is very useful for drawing of the game. However,
 * it fails with elements such like texts. If we want to place something
 * in the middle of screen, it's impossible with this coordinate system.
 * 
 * This is the reason why this class was created. It uses "virtual coordinates",
 * where left up corner of the window is [0.0f, 0.0f] and size of the screen
 * in both axis is equal to 1.0f.
 * 
 * Left up corner:		[0; 0]
 * Right up corner:		[1; 0]
 * Left down corner:	[0; 1]
 * Right down corner:	[1; 1]
 * 
 * @author Tomas Zima
 */
public class Coordinator implements Serializable
{
	/**
	 * This recalculates "virtual coordinates" to the real coordinates.
	 * In virtual coordinates, width and height of the screen are 1.0f.
	 * Coordinate [0; 0] is in the left up corner. If you want to draw
	 * a pixel exactly in the middle of the screen, then it will be [0.5f; 0.5f].
	 * 
	 * @param x
	 * @param y
	 * @return
	 */
	public static Coordinates2D getRealCoordinates(float x, float y)
	{
		int screenWidth		= Configuration.WINDOW_WIDTH;
		int screenHeight	= Configuration.WINDOW_HEIGHT;
		
		int realX = (int) (x * screenWidth);
		int realY = (int) (y * screenHeight);
		
		Coordinates2D result = new Coordinates2D(realX, realY);
		return result;
	}
}
